import cv2
import numpy as np

img = np.zeros((200,230),np.uint8)
imgs = np.zeros((200,230),np.uint8)
img[40:100,60:150] = 255
imgs[20:120,20:120] = 128
cv2.imshow('img',img)
cv2.imshow('imgs',imgs)
# 非运算
new_img = cv2.bitwise_not(img)
cv2.imshow('new_img',new_img)
# 与运算
new_imgs = cv2.bitwise_and(img,imgs)
cv2.imshow('new_imgs',new_imgs)
# 或运算
new_imgs = cv2.bitwise_or(img,imgs)

cv2.waitKey(0)